const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

const toSearch = () => {
  wx.navigateTo({
    url: '/pages/search/search',
  })
}

const _getStorage = (key) => {
  return new Promise((resolve, reject) => {
    wx.getStorage({
      key,
      success (res) {
        resolve(res.data)
      }
    })
  })
}

const _setStorage = (key, data) => {
  wx.setStorage({key, data})
}

const _removeStorage = (key) => {
  return new Promise((resolve, reject) => {
    wx.removeStorage({
      key,
      success() {
        resolve()
      }
    })
  })
}
module.exports = {
  formatTime,
  toSearch,
  _getStorage,
  _setStorage,
  _removeStorage
}
